import { ref } from 'vue'
import { defineStore } from 'pinia'
import { loginAPI } from '@/apis/user';


export const useUserStore = defineStore('user', () => {
  // 1.state 2.action 3.return
  const userInfo = ref({})
  const getUserInfo = async ({ account, password }) => {
    const res = await loginAPI({ account, password })
    userInfo.value = res.result

  }
  //退出时清空用户信息
  const logout = () => {
    userInfo.value = {}
  }
  return {
    userInfo,
    getUserInfo,
    logout

  }
}, {
    persist: true,/* 持久化 */
})